<?php
class contWrite extends coreController
{
    protected $template = 'sample2';
    
    public function index()
    {
        Ui(':uipackBootstrap')->plugin('Validator', array(
        	'form' => 'write_form'
        ));
        
        $this->view('write');
    }
    
    public function save()
    {
        $this->setTemplate(null);
        
        $sSubject = r()->getParam('subject', 'post');
        $sContents = r()->getParam('contents', 'post');
        
        if ($this->model('Example')->write($sSubject, $sContents) === true) {
            echo utilJavascript::getInstance()->locationReplace('/index.php');
        } else {
            echo utilJavascript::getInstance()->historyBack('글 작성에 실패하였습니다.');
        }
    }
    
    public function delete()
    {
        $this->setTemplate(null);
        
        $iIdx = r()->getParam('idx');
        
        if ($this->model('Example')->delete($iIdx) === true) {
            echo utilJavascript::getInstance()->locationReplace('/index.php');
        } else {
            echo utilJavascript::getInstance()->historyBack('글 삭제에 실패하였습니다.');
        }
    }
}